#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>

#define MAX_URL_LEN 2048
 
int get_id_by_url(const char *url, int *id)
{
    int ret = 0;
    char tmp_buf[MAX_URL_LEN] = {0};
    char *p = NULL;

    if (NULL == url || !strlen(url))
    {
        return -1;
    }

    snprintf(tmp_buf, MAX_URL_LEN, "%s", url);
    p = strrchr(tmp_buf, '.');
    if (NULL == p)
    {
        return -1;
    }
    *p = '\0';
    p = strrchr(tmp_buf, '/');
    if (NULL == p)
    {
        return -1;
    }

    p++;
    *id = atoi(p);

    return ret;
}

int main(int argc, char *argv[])
{
    unsigned char url[MAX_URL_LEN] = "/data/123/123.lrc";
    int id = 0;

    if (argc > 1 && 0 != argv[1][0])
    {
        snprintf(url, MAX_URL_LEN, "%s", argv[1]);
    }

    get_id_by_url(url, &id);
    printf ("value:%s\n", url);
    printf("id is: %d\n", id);

    return 0;
}
